package com.hscy.push.controller.request;
import cn.jiyun.common.config.Result;
import cn.jiyun.entity.XmAudit;
import cn.jiyun.entity.XmNotification;
import com.alibaba.fastjson.JSON;
import com.hscy.push.MessageOpenFeign;
import com.hscy.push.service.PushService;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @className: PushMessageContoller
 * @description: 测试消息推送
 * @author: xuteng
 * @date: 2023/12/30 23:25:11
 * @version: v1.0
 */
@RestController
@RequestMapping("/push")
@CrossOrigin
public class PushMessageController {
    @Resource
    private PushService pushService;
    @Resource
    private MessageOpenFeign messageOpenFeign;
    @GetMapping("/message")
    public Result pushMessage(Integer id) {
        XmNotification notification = messageOpenFeign.findById2(id);
        pushService.pushUser(JSON.toJSONString(notification), "1");
//        pushService.pushUser("小程序发送成功！", "1");
        System.out.println("发送成功");
        return Result.ok("小程序发送成功！");
    }


    @PostMapping("/message2")
    public Result pushMessage2(@RequestBody XmAudit xmAudit) {
        xmAudit.setUpdatetime(LocalDateTime.now());
        xmAudit.setNotificationType("系统通知");
        String s=xmAudit.getStatus()==3?"审核通过，你可以重新登录查看":"审核未通过，如需要请重新提交审核";
        xmAudit.setNotificationTitle("你要修改的名称/头像"+s);
        System.out.println(xmAudit+"_________");
        pushService.pushUser(JSON.toJSONString(xmAudit), "1");
        return Result.ok("小程序发送成功！");
    }
}
